using DataBase.Utils;
using GreenXi.Job;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Specialized;
using System.Linq;

namespace GreenXi.Help
{
    /// <summary>
    /// 定时任务类
    /// zyw
    /// 2023-9-4
    /// </summary>
    public class ScheduledTasks
    {
        public static void RegisterJobEntrance()
        {
            #region 创建Job
            var properties = new NameValueCollection { ["quartz.threadPool.threadCount"] = "50" };
            IScheduler scheduler = new StdSchedulerFactory(properties).GetScheduler().Result;

            // 配置线程池大小

            #region 定时更新实时数据
            var job_HeartBeat = JobBuilder.Create<HeartBeatJob>().WithIdentity("HeartBeatJob", "HeartBeatJob").Build();
            scheduler.ScheduleJob(job_HeartBeat, HeartBeatJob.GetTrigger());
            #endregion


            //#region 定时获取电流
            var job_Receiece = JobBuilder.Create<ReceiceJob>().WithIdentity("ReceiceJob", "ReceiceJob").Build();
            scheduler.ScheduleJob(job_Receiece, ReceiceJob.GetTrigger());
            

            #region 定时保存曲线
            var job_SaveCurve = JobBuilder.Create<SaveCurveJob>().WithIdentity("SaveCurveJob", "SaveCurveJob").Build();
            scheduler.ScheduleJob(job_SaveCurve, SaveCurveJob.GetTrigger());
            #endregion


            #region 备份定时任务
            var job_Backup = JobBuilder.Create<BackupJob>().WithIdentity("BackupJob", "BackupJob").Build();
            scheduler.ScheduleJob(job_Backup, BackupJob.GetTrigger());
            #endregion


            //启动任务
            scheduler.Start();
            #endregion
        }
    }
}
